package com.example.onlinemusic.Controller;

import com.example.onlinemusic.mapper.UserMapper;
import com.example.onlinemusic.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: H_tao_X
 * Date: 2022-12-03
 * Time: 17:37
 */

@RestController // 组合注解：@Controller + @ResponseBody
@RequestMapping("/user") // 一级路由

public class UserController {

    /**
     * 用户登录功能
     */

    @Autowired
    private UserMapper userMapper; // 将 UserMapper对象注入

    @RequestMapping("/login")
    public void login(@RequestParam String username,@RequestParam String password) {

        // 1.先拿到 User 对象
        User userLogin = new User();
        // 2.设置 username 和 password
        userLogin.setUsername(username);
        userLogin.setPassword(password);
        // 3.调用 mapper里面的 login方法去数据库查询
        User user = userMapper.login(userLogin); // 调用userMapper的登录方法

        // 4.进行判断
        if(user != null) {

            System.out.println("登录成功");
        }else {

            System.out.println("登录失败");
        }

    }
}
